<?php
namespace app\admin\controller;
use think\Controller;
use think\Controllers;

use think\Session;
use think\Cookie;
use think\Jump;
use think\Db;

class Article extends Controllers{

	public function index(){

	$pindex    = max(1, intval($_REQUEST['page']));

	$psize     = 20;


	
	$wheres = " AND uniacid=2 ";

	if(!empty($_REQUEST['id'])){

		$wheres.=" and id = '{$_REQUEST['id']}' ";
		$this->assign("id",$_REQUEST['id']);
		
	}

	if(!empty($_REQUEST['name'])){

		$wheres.=" and title LIKE '%".$_REQUEST['name']."%'";
		$this->assign("id",$_REQUEST['name']);

		
	}
	$sql = "SELECT * FROM ims_xuan_zy_article WHERE  1 {$wheres} and lanmu!=-6 order by id desc";
	$sql .= " limit " . ($pindex - 1) * $psize . ',' . $psize;

	$list = DB::query($sql);
	$count  = DB::query("select count(*) as count from ims_xuan_zy_article WHERE 1 {$wheres} and lanmu!=-6 ")[0]['count'];
	$this->assign("list",$list);
	$this->assign("count",$count);
	return $this->fetch("admin/article");
	

	}
	public function add(){
		if(request()->isget()){
		$id =$_REQUEST['id'];
		$sql ="select * from ims_xuan_zy_article where id = {$id}";
		$arr = DB::query($sql)[0];
		$this->assign("arr",$arr);
		return	$this->fetch("admin/article_add");
		} else {
			$_POST['da']['create_time'] = date("Y-m-d H:i:s",time());
			$_POST['da']['uniacid'] = 2;
			if($_REQUEST['id']){
				DB::table("ims_xuan_zy_article")->where("id",$_POST['id'])->setField($_POST['da']);
				  $this->success("修改成功","admin/article/index");
				
			}else {
		  DB::table("ims_xuan_zy_article")->insert($_POST['da']);
		  $this->success("添加成功","admin/article/index");
				
			}
		}

	}
	public function del(){
		$id = $_REQUEST['id'];
		$sql = "delete from ims_xuan_zy_article where id = {$id} ";
		DB::query($sql);
		return true;
	}
}